package com.enterprise.viewer.client.event;

import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.GwtEvent.Type;
import com.google.gwt.event.shared.SimpleEventBus;

public class MasonryEvent {
	
	public static enum EVENTTYPE {REQUEST, RESPONSE, BROADCAST};
	public static enum CATEGORY {GET, SET, CHANGED};
	public static enum NAME {REFRESH};	
	
	public static Type<_EventHandler> TYPE = new Type<_EventHandler>();
	
	public static interface _EventHandler extends EventHandler {
		void onChange(_Event event);
	}

	public static class _Event extends GwtEvent<_EventHandler> {

		private EVENTTYPE type;
		private CATEGORY category;
		private NAME name;
		private Object[] params;

		public _Event(EVENTTYPE type, CATEGORY category, NAME name, Object[] params) {
			this.type = type;
			this.category = category;
			this.name = name;
			this.params = params;
		}

		@Override
		public Type<_EventHandler> getAssociatedType() {
			return TYPE;
		}

		@Override
		protected void dispatch(_EventHandler handler) {
			handler.onChange(this);
		}

		public EVENTTYPE getType() {
			return type;
		}
		
		public CATEGORY getCategory() {
			return category;
		}
		
		public NAME getName() {
			return name;
		}
		
		public Object[] getParams() {
			return params;
		}
	}
	
	public static void fireEvent(SimpleEventBus eventBus, EVENTTYPE type, CATEGORY category, NAME name, Object[] params){
		eventBus.fireEvent(new MasonryEvent._Event(type, category, name, params));
	}
}
